﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FB.Bussiness;
using FB.Utilities;

namespace FB.admin
{
    public partial class VideoCategoryList : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CheckPermission();
                LoadData();
            }
        }
        private void CheckPermission()
        {
            if (Page.User.IsInRole(Constants.ROLE_ADMINISTRATOR)
                || Page.User.IsInRole(Constants.ROLE_AUTHOR)
                || Page.User.IsInRole(Constants.ROLE_CONTRIBUTER)
                || Page.User.IsInRole(Constants.ROLE_EDITOR))
            {
                //
            }
            else
            {
                Response.Redirect("/admin/AccessDenied.aspx");
            }
        }
        private void LoadData()
        {
            //Read all VideoCategory
            VideoCategoryBO Bo = new VideoCategoryBO();
            rptData.DataSource = Bo.GetAllVideoCategory();
            rptData.DataBind();
        }
        protected void btnAdd_Click(Object sender, EventArgs e)
        {
            Response.Redirect("VideoCategoryModify.aspx?ID=0");
        }
        protected void btnEdit_Click(Object sender, EventArgs e)
        {
            string EditID = "-1";
            foreach (RepeaterItem ri in rptData.Items)
            {
                CheckBox chk = (CheckBox)ri.FindControl("chkItem");
                if (chk.Checked)
                {
                    EditID = chk.Attributes["value"];
                }
            }
            Response.Redirect("VideoCategoryModify.aspx?ID=" + EditID);
        }
        protected void btnDelete_Click(Object sender, EventArgs e)
        {
            VideoCategoryBO BO = new VideoCategoryBO();
            foreach (RepeaterItem ri in rptData.Items)
            {
                CheckBox chk = (CheckBox)ri.FindControl("chkItem");
                if (chk.Checked)
                {
                    BO.DelVideoCategory(Guid.Parse(chk.Attributes["value"]));
                }
            }
            LoadData();
        }
        protected void btnPublish_Click(Object sender, EventArgs e)
        {

        }
        protected void btnUnpublish_Click(Object sender, EventArgs e)
        {
        }
    }
}